In the SpriteWorld files->Utils->Brian's Extensions folder are some free extensions to SpriteWorld that I've been working on in my free time. They allow sprites which are translucent, scaled or rotated. There are also files for doing several different kinds of lighting effects. Each file has fairly extensive comments and documentation. In general, each file has general documentation at the top and function specific documentation with the functions. They have been tested to work with 68K and PowerPC Macintoshes, and have been optimized in some cases with PowerPC assembly code. They work in 8-Bit or 16-Bit color (i.e. 256 colors or Thousands of Colors).
To use these, you simply include the files in your project file.
Also note that translucency, scaling and rotation cannot be combined. That is, you can't have a scaled translucent sprite. Although this wouldn't be to hard for the avid programmer. The blitters are fairly well commented.
In addition, none of these extensions were designed to work in a scrolling world. You can try to get them to work in a scrolling game, but there are no guarantees that they will work. Generally, any functions that don't work right when clipping is used won't work properly in a scrolling world. (Such as scaling and rotating.) Translucency and other lighting effects might work in a scrolling game, but haven't been tested.
The Extended Sprite Test shows how all of this functionality except the tinting works. The Lighting Demo shows how tinting works. Lit Breakout is a more detailed example of the LightingSquares functionality. All demos and code has been built and tested with Think C 6.0, CodeWarrior 10, and CodeWarrior Pro 5. The demos are not included in the main SpriteWorld package, but are included in the SpriteWorld Extra Demos package.
Below I've copied sections from the top of each source file so you can see the basic documentation all in this one file:
** N.B. These functions are still relatively experimental. They work fine, but the public API needs work to achieve better effects and uses.
These routines are for an alternative style of getting lighting effects. It's main function is a Screen Blitting procedures that takes the offscreen work area and colors it as it copies it on screen. Thus the parts copied on screen can be made darker or lighter or a little reddish, etc.
To support a feeling of lights, we divide the screen into a map of tiny squares and associate a color and a level with each square. As we blit onto the screen, we use this map to color the image. The result is that the screen image looks nicely colorized. Imagine each square having a colored gel placed over top of it.
The smaller the squares in our map, the finer the grain of lighting but the greater the overhead. More space and speed are required. We also provide routines for setting and managing this lighting map, including setting light levels and combining lights (so blue lights and yellow lights will become greenish lights as they overlap).
These functions make use of the translucency table functions found in "SWTranslucentBlitters.c" and therefore that file needs to be present for this to work.
Use SWInitializeLightingSquares(spriteWorldPtr, 8); to initialize the use of squares. 8 in this case is the size of the squares in pixels.
to set a cell's value. Opacity is the translucency levels (as in the translucent blitters). relativeP is a boolean specifying whether to set the color and level directly or to blend it together with what is already in the cell. makeDirtyP forces sprite world to redraw that cell on the screen during the next draw loop.
Use:
SWLightUpArea (spriteWorldPtr, col, row,
color, level
bigLightP);
to light up an area around a cell. This is good for spotlights. bigLightP makes the light really big. Note that this just calls SWSetLightingSquare repeatedly.
SWDarkenLightingSquares (spriteWorldPtr); will blend black into every square in the grid to darken everything. This is a good example of how to achieve a lighting effect with these squares.
Use
SWExitLightingSquares ();
to free up the tables when quitting.
You may use these routines in a scrolling game, provided that you scroll in
multiples of the lighting grid.
The Lit Breakout Demo is an example of how to use these functions in an app.
- Functions for tinting SpriteWorld graphics a particular color.
- Functions for using tinting to implement basic lighting techniques on
sprites and tiles.
This style of lighting works well with tiles with a single kind of light. This is because we precompute all of the sprites and tiles at the different light levels. This makes it fast, but not very flexible. See "SWLightingSquares.c" for another approach to lighting which is slightly slower, but is dynamic and handles an arbitrary number of colored lights.
Functionality documented above each function. See the Lighting Demo for a representative example of how to use everything.
This is all provided as is with no promises or guarantees. Don't count on me for support, service, or coherency. And don't blame anyone else for my mistakes. Thanks are always appreciated. Drop me a line if this stuff is useful.